package com.woniuxy.cloud.carl.carlstation.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniu.cloud.Aspect.log.Log;
import com.woniuxy.cloud.carl.carlstation.client.NoticeClient;
import com.woniuxy.cloud.carl.carlstation.client.dto.NoticeDto;
import com.woniuxy.cloud.carl.carlstation.client.param.AddNoticeParam;
import com.woniuxy.cloud.carl.carlstation.client.param.DelNoticeParam;
import com.woniuxy.cloud.carl.carlstation.client.param.GetNoticeParam;
import com.woniuxy.cloud.carl.carlstation.service.NoticeService;
import com.woniuxy.cloud.carl.carlstation.service.dto.NoticeServiceDto;
import com.woniuxy.cloud.carl.carlstation.service.param.NoticeServiceParam;
import com.woniuxy.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class NoticeAPIImpl implements NoticeClient {
    @Autowired
    NoticeService noticeService;
    @Override
    @Log("新增公告")
    public Result addNotice(AddNoticeParam param) {
        NoticeServiceParam noticeServiceParam = BeanUtil.copyProperties(param, NoticeServiceParam.class);
        return noticeService.addNotice(noticeServiceParam);
    }

    @Override
    @Log("删除公告")
    public Result delNotice(DelNoticeParam param) {
        noticeService.delNotice(param.getNoticeIds());
        return noticeService.delNotice(param.getNoticeIds());
    }

    @Override
    @Log("查询公告")
    public Result<List<NoticeDto>> getNotice(GetNoticeParam param) {
        Result<List<NoticeServiceDto>> notice = noticeService.getNotice(param.getNoticeId(), param.getCondition());
        List<NoticeServiceDto> data = notice.getData();
        ArrayList<NoticeDto> noticeDtos = new ArrayList<>();
        if (data==null) return Result.fail("查询结果为空");
        for (NoticeServiceDto datum : data) {
            NoticeDto noticeDto = BeanUtil.copyProperties(datum, NoticeDto.class);
            noticeDtos.add(noticeDto);
        }
        return Result.success(noticeDtos);
    }

}
